package io.renren.wh.channel.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.wh.channel.entity.ChannelConfigEntity;
import io.renren.wh.channel.service.ChannelConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


@Api(value = "通道配置类接口", tags = {"通道配置类接口"})
@RestController
@RequestMapping("wh/channelconfig")
public class ChannelConfigController {
    @Autowired
    private ChannelConfigService channelConfigService;

    /**
     * 列表
     */
    @ApiOperation(value = "查看通道配置列表信息", notes = "查看通道配置列表信息", httpMethod = "POST")
    @RequestMapping("/list")
    @RequiresPermissions("wh:channelconfig:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = channelConfigService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation(value = "根据通道id查询通道配置信息", notes = "根据通道id查询通道配置信息", httpMethod = "GET")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("wh:channelconfig:info")
    public R info(@PathVariable("id") Integer id){
		ChannelConfigEntity channelConfig = channelConfigService.queryByChannleId(id);

        return R.ok().put("channelConfig", channelConfig);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "新增通道配置", notes = "新增通道配置", httpMethod = "POST")
    @RequestMapping("/save")
    @RequiresPermissions("wh:channelconfig:save")
    public R save(@RequestBody ChannelConfigEntity channelConfig){
		channelConfigService.save(channelConfig);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ApiOperation(value = "修改通道配置信息",notes = "修改通道配置信息",httpMethod = "PUT")
    @RequiresPermissions("wh:channelconfig:update")
    public R update(@RequestBody ChannelConfigEntity channelConfig){
        channelConfigService.updateByChannleId(channelConfig);
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除通道配置信息",notes = "删除通道配置信息",httpMethod = "DELETE")
    @DeleteMapping("/delete")
    @RequiresPermissions("wh:channelconfig:delete")
    public R delete(@RequestBody Integer[] ids){
		channelConfigService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
